package com.yj.consumer.controller;

import com.yj.consumer.service.PaymentService;
import com.yj.pojo.Payment;
import com.yj.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    private PaymentService paymentService;

    //创建支付订单的接口
    @GetMapping("/payment/create")
    public Result<Payment> create(Payment payment) {
        return paymentService.create(payment);
    }

    //获取id获取支付订单
    @GetMapping("/payment/get/{id}")
    public Result<Payment> getPayment(@PathVariable("id") Long id) {
        return paymentService.queryById(id);
    }

    @GetMapping("/payment/timeout")
    public String paymentTimeOut() throws InterruptedException {
        return paymentService.paymentTimeOut();
    }

    @GetMapping("/payment/error")
    public String paymentError() throws InterruptedException {
        return paymentService.paymentError();
    }
}
